/**
 * Created with IntelliJ IDEA.
 * Description:汉诺塔
 * User: xwl
 * Date: 2023-04-03
 * Time: 13:53
 */

public class HanNuoTa {
    //汉诺塔
    public static void main(String[] args) {
        //n=1 A->C
        //n=2 A->B A->C B->C
        //n=3 A->C A->B C->B A->C B->A B->C A->C
        hanNuoTa(1,'A','B','C');
        System.out.println();
        hanNuoTa(2,'A','B','C');
        System.out.println();
        hanNuoTa(3,'A','B','C');
        System.out.println();
    }
    //n个盘子借组pos2，从pos1转移到pos3（大的在下方）
    public static void hanNuoTa(int n, char pos1, char pos2, char pos3) {
        if(n == 1) {
            move(pos1,pos3);
            return ;
        }else {
            //n-1个盘子借组pos3，从pos1转移到pos2
            hanNuoTa(n-1,pos1,pos3,pos2);
            //把pos1的盘子移动到pos3
            move(pos1,pos3);
            //n-1个盘子借组pos1，从pos2转移到pos3
            hanNuoTa(n-1,pos2,pos1,pos3);
        }
    }
    //把盘子从pos1移动到pos2
    public static void move(char pos1, char pos2) {
        System.out.print(pos1+"->"+pos2+" ");
    }

}


